<?php
include_once 'conn.php';
$page = $_GET['page'] ?? 1;
$limit = $_GET['limit'] ?? 5;
$start = ($page - 1) * $limit;
$sql = "select * from carinfo";
$result = mysqli_query($conn,$sql);
$total = mysqli_num_rows($result);
$sql = "select * from carinfo where ok = 1 order by id desc limit $start,$limit ";
$result = mysqli_query($conn,$sql);
$a = array();
if(mysqli_errno($conn)){
    //说明查询出错
    $a['code'] = -1;
    $a['msg'] = '查询数据库出错';
}
else{
    $a['code'] = 0;
    $a['msg'] = '';
    $a['count'] = $total;
    $a['data'] = array();
    $i = 1;
    while ($info = mysqli_fetch_array($result)){
        $b = array();
        $b['no'] = $i;
        $b['id'] = $info['id'];
        $b['carName'] = $info['carName'];
        $b['carDesc'] = $info['carDesc'];
        $b['carPIC'] = "<img style='width:100%' src='img/".$info['carPIC']."'>";
        $b['carNum'] = $info['carNum'];
        array_push($a['data'],$b);
        $i++;
    }
}
echo json_encode($a);